
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <title>{$novel.name}</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="dns-prefetch" href="https://wepay.weipinchu.com/" />
    <link href="https://at.alicdn.com/t/font_fsk2otdio7ds4i.css" rel="stylesheet">
    <link rel="stylesheet" href="https://ommdq027l.qnssl.com/static/release/1500311086095/vendor.css" />
    <link rel="stylesheet" href="https://ommdq027l.qnssl.com/static/release/1500311086095/front.css" />
      <link href="/novel.css" rel="stylesheet">
    <script src="https://ommdq027l.qnssl.com/static/release/1500311086095/vendor.js"></script>
    <script src="https://ommdq027l.qnssl.com/static/release/1500311086095/app.js"></script>
    <script>
      var fromChannelMp = false;
      if (fromChannelMp) {
        LocalCache.remove('profile');
      }
    </script>
    <script type="text/html" id="tmpl-thumb-novel-list">
      <div class="thumb-novel-list">
        {{#each novels}}
        <div class="novel-item">
          <div class="novel-image">
            <a href="/read/intro/{{id}}"><img src="{{avatar}}"/></a>
            {{#if is_time_limited_free}}
              <i class="iconfont icon-time-limited-free"></i>
            {{/if}}
          </div>
          <div class="novel-name">
            <a href="/read/intro/{{id}}">{{truncate title 6}}</a>
          </div>
        </div>
        {{/each}}
      </div>
    </script>
    <script>
      var HandlebarTemplates = {
        _cache: {},

        get: function (name) {
          if (!this._cache[name]) {
            this._cache[name] = Handlebars.compile($('#' + name).html());
          }

          return this._cache[name];
        }
      }
    </script>

    <script>
      var _hmt = _hmt || [];
      (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?d5e4918c33053db244a223b60906a4d3";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();
    </script>
  </head>
  <body class=" ">
    <include file="Public/menu"/>
    <div class="container" style="padding-bottom:0">
    <div class="novel-detail">
        <div class="bd">
            <div class="novel-intro">
                <div class="novel-cover">
                    <img src="{:C('FILE_HOST_PATH')}{$novel.img}" width="105" onerror="this.src='/Public/attached/other/img_error.jpg'">
                </div>
                <div class="novel-info">
                    <h1 class="novel-title text-primary">{$novel.name}</h1>
                    <div class="novel-meta">
                        字数: {$novel.word_count}字
                    </div>
                </div>
            </div>
            <div class="novel-summary block">
                <h6><i class="iconfont icon-introduce"></i><span>简介</span></h6>
                <p>{$novel.description}</p>            
            </div>

            <div class="weui_btn_area">
                <a class="weui_btn weui_btn_primary" href="/Home/Novel/show/id/{$chapter_id}/novel_id/{$novel.id}">开始阅读</a>
            </div>

            <div class="novel-catalog block">
                <div class="catalog-header">
                    <h6><i class="iconfont icon-book"></i><span>目录</span></h6>
                </div>
                <div class="weui_cells">
                	<foreach name="pre_chapter_list" item="vo">
                		<a class="weui_cell" href="/Home/Novel/show/id/{$vo.id}/novel_id/{$novel.id}">{$vo.chapter} {$vo.title}</a>
                	</foreach>
                </div>
                <div class="catalog-footer">
                    <a class="btn-see-more" href="/Home/Novel/novelcatalog/id/{$novel.id}">全部目录</a>
                </div>
            </div>

            <div class="novel-tip block" <?php $_SESSION['user']?'':"style='display:none'"?>>
                <div class="mod-tip">
                    <div class="bubble">
                        <span>打赏</span>
                        <hr>
                        <span class="sum_of_tip" id="sum_of_tip1">{$total_money?$total_money:'0'}</span>
                    </div>
                    <a class="btn-tip-menu" href="javascript:;" >打赏</a>
                    <div class="tip-history">
                        <h6 class="title">打赏记录</h6>
                        <div class="hr1"></div>
                        <?php if(empty($total_money)):?>
                        <div class="no-data" style="">土豪,求打赏</div>
                        <?php endif;?>
                        <div class="rows"></div>
                        <a class="weui_btn weui_btn_default btn-load-more" href="javascript:;">查看更多</a>
                    </div>
                    <script type="text/html" id="tmpl-gifts">
  <ul class="actionsheet-tip">
    {{#each gifts}}<li>
      <a class="btn-gift" data-gift-id="{{id}}">
        <img src="{{img_url}}" alt="{{title}}">
        <span class="text"><span class="price">{{wealth}}</span>书币</span>
      </a>
    </li>{{/each}}
  </ul>
</script>

<script>

  (function (global) {
    var gifts = [{"id":1,"title":"\u9c9c\u82b1","img_url":"https:\/\/ommdq027l.qnssl.com\/static\/gifts\/gift_1.jpg","wealth":100},{"id":2,"title":"\u638c\u58f0","img_url":"https:\/\/ommdq027l.qnssl.com\/static\/gifts\/gift_2.jpg","wealth":388},{"id":3,"title":"\u94bb\u6212","img_url":"https:\/\/ommdq027l.qnssl.com\/static\/gifts\/gift_3.jpg","wealth":588},{"id":4,"title":"\u6e38\u8f6e","img_url":"https:\/\/ommdq027l.qnssl.com\/static\/gifts\/gift_4.jpg","wealth":888}];

    global.Tip = function () { };

    _.extend(Tip.prototype, {
      open: function () {
        var me = this;
        $.actions({
          title: '打赏',
          actions: [{
            className: 'bg-white',
            text: HandlebarTemplates.get('tmpl-gifts')({
              gifts: gifts
            })
          }]
        });

        $('.actionsheet-tip').on('click', '.btn-gift', function () {
          var gift = _.find(gifts, { id: parseInt($(this).data('gift-id')) });
          // 由于当actionshhet关闭时，jquery-weui会将modal的遮罩css也一起删除，因此需要做这个hack
          // https://github.com/lihongxun945/jquery-weui/blob/master/src/js/action.js#L50
          setTimeout(function () {
            me.create(gift);
          }, 50);
        });
      },
      create: function (gift) {
        var me = this;
        $.actions({
          title: '确定打赏?',
          actions: [{
            text: '确定',
            className: 'color-primary',
            onClick: function () {
              $.ajax({
                url: '{:U("novel/dashang")}',
                type: 'POST',
                dataType: 'JSON',
                data: {
                    gift_id:gift.id,
                    novel_id:{$novel['id']},
                },
                success:function (data) {
                    if(data.status == 200) {
                        $('#sum_of_tip1').text(data.money);
						$('.no-data').attr('style','display:none');
                        $('.hr1').prepend('<div class="contentbox"><div class="leftbox"><div class="imgicos"><img src="' + data.img + '"></div></div><div class="rightbox"><h4>' + data.nickname + '</h4><p style="color: #ff9224">赠送<img style="width: 20px;" src="https://ommdq027l.qnssl.com/static/gifts/gift_' + data.das_pic + '.jpg">x1个礼物给作者</p><p style="color: #E8E8E8">' + data.time + '</p></div></div>');
                    }else{
					
                            $.modal({
                                title: "余额不足",
                                text: " 是否前往充值?",
                                buttons: [{
                                    text: "立即充值",
                                    onClick: function () {
                                        window.onpageshow = function (e) {
                                            if (e.persisted) {
                                                location.reload();
                                            }
                                        };
                                        location.assign('http://shacr.cn/Home/User/recharge?' + $.param({
                                            "gift_id": gift.id,
                                            "return": '/read/intro/199?tip=1'
                                        }));
                                    }
                                }, {
                                    text: "取消",
                                    className: "default"
                                }]
                            });
                    }
                }

              })
            }
          }]
        });
      },
     
    });
  })(window);
</script>
                    <script type="text/html" id="tmpl-tip-history">
                        <div class="row">
                          <div><img class="avatar" src="{{ headimgurl }}" alt="{{ nickname }}"></div>
                          <div class="detail">
                            <p class="nickname">{{ nickname }}</p>
                            <div class="gift">赠送: <img src="{{ gift_img_url }}" alt="{{ gift_name }}"> × 1 个礼物给作者</div>
                            <div class="datetime">{{timestamp created_at 'YYYY-MM-DD HH:mm'}}</div>
                          </div>
                        </div>
                    </script>
                    <script>
                        $(function () {
                          var pageSize = 5;

                          function TipHistory() {
                            _.extend(this, {
                              page: 0,
                              loading: false,
                              completed: false,
                              items: []
                            });
                          }

                          _.extend(TipHistory.prototype, {
                            init: function () {
                              this.loadMore();
                              $('.btn-load-more').on('click', function () {
                                tiphistory.loadMore();
                              });
                            },
                            loadMore: function () {
                              var me = this;
                              var data = {
                                page: ++me.page,
								novel_id:{$novel['id']},
                              };

                              me.loading = true;
                              return $.ajax({
                                url: "http://shacr.cn/Home/Novel/loadmore?" + $.param(data),
                                type: 'GET',
                                dataType: 'JSON',
                                contentType: 'application/json',
                                  success:function (data) {
                                      $.each(data,function (index,obj) {
                                          $('.hr1').append('<div class="contentbox"><div class="leftbox"><div class="imgicos"><img src="' + obj.img + '"></div></div><div class="rightbox"><h4>' + obj.nickname + '</h4><p style="color: #ff9224">赠送<img style="width: 20px;" src="https://ommdq027l.qnssl.com/static/gifts/gift_' + obj.das_pic + '.jpg">x1个礼物给作者</p><p style="color: #E8E8E8">' + obj.time + '</p></div></div>');
                                      });
                                  }
                              })
                            },
                            render: function (data, prepend) {
                              this.items = _.union(this.items, data);

                              if (this.completed) {
                                $('.btn-load-more').hide();
                              }

                              $('.tip-history .rows')[this.items.length ? 'show' : 'hide']();
                              $('.tip-history .no-data')[this.items.length ? 'hide' : 'show']();

                              var fn = HandlebarTemplates.get('tmpl-tip-history');
                              var html = _.map(data, function (it) {
                                it.nickname = it.nickname || '匿名';
                                it.headimgurl = it.headimgurl || '//ommdq027l.qnssl.com/static/guest.jpg';
                                return fn(it);
                              });
                              $('.tip-history .rows')[prepend ? 'prepend' : 'append'](html);
                            }
                          });

                          $(document).on('inovel.tip.created', function (event, data) {
                            refreshStats();
                            tiphistory.render([data], true);
                          });

                          function refreshStats () {
                            return $.ajax({
                                url: '/api/novels/sum_of_tip/199',
                                type: 'GET',
                                dataType: 'JSON',
                                contentType: 'application/json'
                              })
                              .then(function (payload) {
                                $('.sum_of_tip').text(payload.data);
                              });
                          }

                          var tiphistory = new TipHistory();                          
                          var tip = new Tip();
                          var hash = qs2hash(location.search);
                          if (hash['tip']) {

                            tip.open();
                          }

                          $('.btn-tip-menu').on('click', _.bind(tip.open, tip));
                          refreshStats();
                          tiphistory.init();
                        });
                      </script> 
                </div>
            </div>
        </div>
    </div>
</div>
    </body>
</html>
